package org.train.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.train.entity.ReportPo;
import org.train.entity.RevenueExpenditurePo;

import java.util.List;

public class AmountUtil{
    public static Amounts calcAmounts(List<RevenueExpenditurePo> list, int currYear){
        Amounts amounts = new Amounts();
        for(RevenueExpenditurePo po: list){
            Double amount = po.getAmount();
            int type = po.getType();
            int year = po.getProjectYear();
            switch(type){
                case 1:
                    amounts.totalBilling += amount;
                    amounts.annualBilling += amount * (currYear == year? 1: 0);
                    break;
                case 2:
                    amounts.totalFundsReceived += amount;
                    amounts.annualFundsReceived+= amount * (currYear == year? 1: 0);
                    break;
                case 10:
                    amounts.totalAdvancePayment+= amount;
                    amounts.annualAdvancePayment+= amount * (currYear == year? 1: 0);
                    break;
                default:
                    amounts.totalExpenditure += amount;
                    amounts.annualExpenditure += amount * (currYear == year? 1: 0);
            }
        }
        return amounts;
    }

    public static class Amounts{
        public double totalBilling; // 累计开票（收入）
        public double annualBilling; // 当年开票
        public double totalExpenditure; // 累计支出
        public double annualExpenditure; // 当年支出
        public double totalFundsReceived; // 累计回款
        public double annualFundsReceived; // 当年回款
        public double totalAdvancePayment; // 累计预付
        public double annualAdvancePayment; // 当年预付
        public double totalGrossProfit(){ // 累计毛利
            return this.totalBilling - this.totalExpenditure;
        }
        public double annualGrossProfit(){ // 当年毛利
            return this.annualBilling - this.annualExpenditure;
        }
        public double receivable(){ // 应收
            return this.totalBilling - this.totalFundsReceived;
        }
        public double needPayment(){ // 应付
            return 0.0; // TODO 得出应付的计算方法
        }
        public double profitRate(){ // 利润率
            if(this.totalBilling == 0){
                return 0;
            }
            return (this.totalBilling - this.totalExpenditure) / this.totalBilling;

        }
    }
}
